package com.smzd.projforge.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.smzd.core.business.AbstractService;
import com.smzd.core.dao.IDao;
import com.smzd.core.utils.json.FGRowConverter;
import com.smzd.projforge.dao.RenderDao;
import com.smzd.projforge.domain.Render;
import com.smzd.projforge.domain.Template;

@Service
public class RenderService extends AbstractService<Render> {
    @Autowired
    private RenderDao dao;
    
    @Override
    protected IDao<Render> getDao() {
        return dao;
    }
    
    @Override
    protected FGRowConverter<Render> getConverter() {
        return converter;
    }

    private static FGRowConverter<Render> converter = new FGRowConverter<Render>() {
        @Override
        public Object[] convert(Render elem) {
            Template template = elem.getTemplate();
            Object[] obj_template;
            if(template==null){
                obj_template = null;
            }else{
                Integer id_template = template.getId();
                String name_template = template.getName();
                obj_template = new Object[]{id_template, name_template};
            }
            Object[] fs = new Object[]{
                    elem.getId(),
                    elem.getName(),
                    elem.getDescription(),
                    elem.getPath(),
                    elem.getFilename(),
                    elem.isSeperate(),
                    obj_template
                };
                return fs;
        }
    };
    
}